package com.scorpio.post;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.scorpio.Db_User;
import com.scorpio.baen.UserInfo;
import com.scorpio.utils.ClientManager;
import com.shooter.dao.DBManager;
import com.shooter.note.Action;
import com.shooter.server.BaseHttpServlet;
import com.shooter.server.ServiceApi;
import com.shooter.server.ServletDispose;
import com.shooter.utils.StringUtil;

import javax.servlet.annotation.WebServlet;
import java.nio.channels.SocketChannel;
import java.util.HashMap;
import java.util.List;

@WebServlet("/call/user/*")
public class UserServlet extends BaseHttpServlet {
    @Action()
    public void register(JSONObject json, ServletDispose dispose) {
        String phone = dispose.getValue("phone");
        String netname = dispose.getValue("netname");
        json.put(ServiceApi.CODE, ServiceApi.CODE_NO);

        if (!StringUtil.checkStringNoNull(phone) && phone.length() < 11) {
            json.put(ServiceApi.MSG, "请输入正确的手机");
            return;
        } else if (!StringUtil.checkStringNoNull(netname) && netname.length() < 10) {
            json.put(ServiceApi.MSG, "请输入名字");
            return;
        }
        Db_User dbUser = new Db_User();
        dbUser.setPhone(phone);
        dbUser.setNetname(netname);
        if (DBManager.insert(dbUser)) {
            json.put(ServiceApi.CODE, ServiceApi.CODE_OK);
        } else {
            json.put(ServiceApi.MSG, "注册失败");
        }
    }
}
